﻿using PPIDataAccess.General;
using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;

namespace PPIDataAccess.Data
{
	public static class DUtility_QueryAsset
	{
		#region Query
        public static DataSet SelectCRUD(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectCRUD", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;

            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectCRUD", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet ExecuteQuery_XMission(Int32 queryAssetFK, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAsset_ExecuteQuery_XMission", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@QueryAssetFK", ParameterDirection.Input, false, queryAssetFK));
                DataSet ds = new DataSet();
                _Da.Fill(ds);
                return ds;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAsset_ExecuteQuery_XMission", _Ex);
            }
            finally
            {
                if (_Da != null) 
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SellectAll_ContactQueries(Int32 contactFK, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAsset_SelectByContact", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@ContactFK", ParameterDirection.Input, false, contactFK));
                DataSet ds = new DataSet();
                _Da.Fill(ds);
                return ds;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAsset_SelectByContact", _Ex);
            }
            finally
            {
                if (_Da != null) 
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectAll(string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectAll", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataSet ds = new DataSet();
                _Da.Fill(ds);
                return ds;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectAll", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }

        #region Cross Tables
        public static DataSet SelectYears(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectYears", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectYears", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectTopTypes(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectTopTypes", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectTopTypes", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectPoleTopTypes(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectPoleTopTypes", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectPoleTopTypes", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectPoleSpecies(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectPoleSpecies", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectPoleSpecies", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectProjects(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectProjects", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectProjects", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectPoleTreatments(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectPoleTreatments", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectPoleTreatments", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectPoleClasses(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectPoleClasses", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectPoleClasses", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectVendors(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectVendors", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectVendors", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        public static DataSet SelectAssets(Int32 utility_QueryAssetId, string connectionKey)
        {
            SqlDataAdapter _Da = null;
            try
            {
                _Da = new SqlDataAdapter("up_Utility_QueryAssets_SelectAssets", DBHelper.GetConnection(connectionKey));
                _Da.SelectCommand.CommandType = CommandType.StoredProcedure;
                _Da.SelectCommand.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                DataSet _Dt = new DataSet();
                _Da.Fill(_Dt);
                return _Dt;
            }
            catch (Exception _Ex)
            {
                throw new Exception("Error executing up_Utility_QueryAssets_SelectAssets", _Ex);
            }
            finally
            {
                if (_Da != null)
                    _Da.SelectCommand.Connection.Close();
            }
        }
        #endregion Cross Tables
        #endregion Query

        #region CRUD
        #region summary
        /// <summary>
        /// Date: 05/26/2008
        /// Time: 14:01:07
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public static Int32 Insert(Int32 utilityFK, Int32 utility_Query_TypeFK, Int32 utility_ContactFK, string name, string color, Int32 textToShow, bool showLineParents, string connectionKey)
        {
            SqlCommand _Cmd = null;
            SqlTransaction _Tr = null;

            try
            {
                _Cmd = new SqlCommand("up_Utility_QueryAssets_Insert", DBHelper.GetConnection(connectionKey));
                _Tr = _Cmd.Connection.BeginTransaction();
                _Cmd.Transaction = _Tr;

                _Cmd.CommandType = CommandType.StoredProcedure;
                #region UtilityFK
                if (utilityFK != Int32.MinValue)
                    _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@UtilityFK", ParameterDirection.Input, true, utilityFK));
                else
                    _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@UtilityFK", ParameterDirection.Input, true, DBNull.Value));
                #endregion UtilityFK
                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_Query_TypeFK", ParameterDirection.Input, false, utility_Query_TypeFK));
                #region Utility_ContactFK
                if (utility_ContactFK != Int32.MinValue)
                    _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_ContactFK", ParameterDirection.Input, true, utility_ContactFK));
                else
                    _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_ContactFK", ParameterDirection.Input, true, DBNull.Value));
                #endregion Utility_ContactFK
                _Cmd.Parameters.Add(DBHelper.CreateNVarCharParameter("@Name", 250, ParameterDirection.Input, false, name));
                _Cmd.Parameters.Add(DBHelper.CreateNVarCharParameter("@Color", 50, ParameterDirection.Input, false, color));
                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@TextToShow", ParameterDirection.Input, false, textToShow));
                _Cmd.Parameters.Add(DBHelper.CreateBitParameter("@ShowLineParents", ParameterDirection.Input, false, showLineParents));

                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.ReturnValue, false, 0));
                _Cmd.ExecuteNonQuery();
                _Tr.Commit();
                return (Int32)_Cmd.Parameters["@Utility_QueryAssetId"].Value;

            }
            catch (Exception)
            {
                if (_Tr != null)
                    _Tr.Rollback();
                throw;
            }
            finally
            {
                if (_Cmd != null) _Cmd.Connection.Close();
            }
        }
        #region summary
        /// <summary>
        /// Date: 05/26/2008
        /// Time: 14:01:07
        /// Generated by: VMCoder
        /// Generated using VirtualGenerator
        /// </summary>
        #endregion summary
        public static void Update(Int32 utility_QueryAssetId, Int32 utilityFK, Int32 utility_Query_TypeFK, Int32 utility_ContactFK, string name, string color, Int32 textToShow, bool showLineParents, string connectionKey)
        {
            SqlCommand _Cmd = null;
            SqlTransaction _Tr = null;


            try
            {
                _Cmd = new SqlCommand("up_Utility_QueryAssets_Update", DBHelper.GetConnection(connectionKey));
                _Tr = _Cmd.Connection.BeginTransaction();
                _Cmd.Transaction = _Tr;
                _Cmd.CommandType = CommandType.StoredProcedure;
                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
                #region UtilityFK
                if (utilityFK != Int32.MinValue)
                    _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@UtilityFK", ParameterDirection.Input, true, utilityFK));
                else
                    _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@UtilityFK", ParameterDirection.Input, true, DBNull.Value));
                #endregion UtilityFK
                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_Query_TypeFK", ParameterDirection.Input, false, utility_Query_TypeFK));
                #region Utility_ContactFK
                if (utility_ContactFK != Int32.MinValue)
                    _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_ContactFK", ParameterDirection.Input, true, utility_ContactFK));
                else
                    _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_ContactFK", ParameterDirection.Input, true, DBNull.Value));
                #endregion Utility_ContactFK
                _Cmd.Parameters.Add(DBHelper.CreateNVarCharParameter("@Name", 250, ParameterDirection.Input, false, name));
                _Cmd.Parameters.Add(DBHelper.CreateNVarCharParameter("@Color", 50, ParameterDirection.Input, false, color));
                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@TextToShow", ParameterDirection.Input, false, textToShow));
                _Cmd.Parameters.Add(DBHelper.CreateBitParameter("@ShowLineParents", ParameterDirection.Input, false, showLineParents));

                _Cmd.ExecuteNonQuery();
                _Tr.Commit();
            }
            catch (Exception)
            {
                if (_Tr != null)
                    _Tr.Rollback();

                throw;
            }
            finally
            {
                if (_Cmd != null) _Cmd.Connection.Close();
            }
        }
        #region Cross Tables
        public static void DeleteYears(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeleteYears", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static void DeleteTopTypes(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeleteTopTypes", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static void DeletePoleTopTypes(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeletePoleTopTypes", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static void DeletePoleSpecies(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeletePoleSpecies", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static void DeleteProjects(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeleteProjects", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static void DeletePoleTreatments(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeletePoleTreatments", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static void DeletePoleClasses(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeletePoleClasses", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static void DeleteVendors(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeleteVendors", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static void DeleteAssets(Int32 utility_QueryAssetId, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_DeleteAssets", tr.Connection);
            _Cmd.Transaction = tr;
            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));

            _Cmd.ExecuteNonQuery();
        }
        public static Int32 InsertYear(Int32 utility_QueryAssetId, Int32 year, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertYear", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Year", ParameterDirection.Input, false, year));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_YearId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_YearId"].Value;
        }
        public static Int32 InsertTopType(Int32 utility_QueryAssetId, Int32 xMissionStructures_TopTypeFk, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertTopType", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@XMissionStructures_TopTypeFk", ParameterDirection.Input, false, xMissionStructures_TopTypeFk));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_XMissionStructures_TopTypeId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_XMissionStructures_TopTypeId"].Value;
        }
        public static Int32 InsertPoleTopType(Int32 utility_QueryAssetId, Int32 xMissionStructures_PoleTopTypeFk, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertPoleTopType", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@XMissionStructures_PoleTopTypeFk", ParameterDirection.Input, false, xMissionStructures_PoleTopTypeFk));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_XMissionStructures_PoleTopTypeId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_XMissionStructures_PoleTopTypeId"].Value;
        }
        public static Int32 InsertPoleSpecies(Int32 utility_QueryAssetId, Int32 xMissionStructures_PoleSpeciesFk, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertPoleSpecies", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@XMissionStructures_PoleSpeciesFk", ParameterDirection.Input, false, xMissionStructures_PoleSpeciesFk));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_XMissionStructures_PoleSpeciesId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_XMissionStructures_PoleSpeciesId"].Value;
        }
        public static Int32 InsertProject(Int32 utility_QueryAssetId, Int32 utility_ProjectFk, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertProject", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_ProjectFk", ParameterDirection.Input, false, utility_ProjectFk));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_ProjectId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_ProjectId"].Value;
        }
        public static Int32 InsertPoleTreatment(Int32 utility_QueryAssetId, Int32 xMissionStructures_PoleTreatmentFk, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertPoleTreatment", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@XMissionStructures_PoleTreatmentFk", ParameterDirection.Input, false, xMissionStructures_PoleTreatmentFk));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_XMissionStructures_PoleTreatmentId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_XMissionStructures_PoleTreatmentId"].Value;
        }
        public static Int32 InsertPoleClass(Int32 utility_QueryAssetId, Int32 xMissionStructures_PoleClassFk, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertPoleClass", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@XMissionStructures_PoleClassFk", ParameterDirection.Input, false, xMissionStructures_PoleClassFk));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_XMissionStructures_PoleClassId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_XMissionStructures_PoleClassId"].Value;
        }
        public static Int32 InsertVendor(Int32 utility_QueryAssetId, Int32 vendorFk, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertVendor", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@VendorFk", ParameterDirection.Input, false, vendorFk));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_VendorId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_VendorId"].Value;
        }
        public static Int32 InsertAsset(Int32 utility_QueryAssetId, Int32 utility_Asset_XMissionStructureFk, SqlTransaction tr)
        {
            SqlCommand _Cmd = null;
            _Cmd = new SqlCommand("up_Utility_QueryAssets_InsertAsset", tr.Connection);
            _Cmd.Transaction = tr;

            _Cmd.CommandType = CommandType.StoredProcedure;
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, utility_QueryAssetId));
            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_Asset_XMissionStructureFk", ParameterDirection.Input, false, utility_Asset_XMissionStructureFk));

            _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAsset_Cross_AssetId", ParameterDirection.ReturnValue, false, 0));
            _Cmd.ExecuteNonQuery();
            return (Int32)_Cmd.Parameters["@Utility_QueryAsset_Cross_AssetId"].Value;
        }
        #endregion Cross Tables
        public static void Delete(Int32 Utility_QueryAssetId, string connectionKey)
        {
            SqlCommand _Cmd = null;
            SqlTransaction _Tr = null;
            try
            {
                _Cmd = new SqlCommand("up_Utility_QueryAssets_Delete", DBHelper.GetConnection(connectionKey));
                _Tr = _Cmd.Connection.BeginTransaction();
                _Cmd.Transaction = _Tr;
                _Cmd.CommandType = CommandType.StoredProcedure;
                _Cmd.Parameters.Add(DBHelper.CreateIntParameter("@Utility_QueryAssetId", ParameterDirection.Input, false, Utility_QueryAssetId));
                _Cmd.ExecuteNonQuery();
                _Tr.Commit();
            }
            catch (Exception _Ex)
            {
                if (_Tr != null)
                    _Tr.Rollback();
                throw new Exception("Error executing up_tb_Utility_QueryAssets_Delete", _Ex);
            }
            finally
            {
                if (_Cmd != null)
                    _Cmd.Connection.Close();
            }
        }
        #endregion CRUD
    }
}
